package com.beigai.imessage.dao.mapper;

import com.beigai.imessage.dao.po.MessageOfflinePO;
import org.apache.ibatis.jdbc.SQL;

public class MessageOfflinePOSqlProvider {

    public String insertSelective(MessageOfflinePO record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("message_offline");
        
        if (record.getMessageFromCode() != null) {
            sql.VALUES("message_from_code", "#{messageFromCode,jdbcType=VARCHAR}");
        }
        
        if (record.getMessageToCode() != null) {
            sql.VALUES("message_to_code", "#{messageToCode,jdbcType=VARCHAR}");
        }
        
        if (record.getMessage() != null) {
            sql.VALUES("message", "#{message,jdbcType=VARCHAR}");
        }
        
        if (record.getMessageSortNum() != null) {
            sql.VALUES("message_sort_num", "#{messageSortNum,jdbcType=INTEGER}");
        }
        
        if (record.getMessageType() != null) {
            sql.VALUES("message_type", "#{messageType,jdbcType=INTEGER}");
        }
        
        if (record.getStatus() != null) {
            sql.VALUES("status", "#{status,jdbcType=INTEGER}");
        }
        
        if (record.getCreateTime() != null) {
            sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            sql.VALUES("update_time", "#{updateTime,jdbcType=TIMESTAMP}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(MessageOfflinePO record) {
        SQL sql = new SQL();
        sql.UPDATE("message_offline");
        
        if (record.getMessageFromCode() != null) {
            sql.SET("message_from_code = #{messageFromCode,jdbcType=VARCHAR}");
        }
        
        if (record.getMessageToCode() != null) {
            sql.SET("message_to_code = #{messageToCode,jdbcType=VARCHAR}");
        }
        
        if (record.getMessage() != null) {
            sql.SET("message = #{message,jdbcType=VARCHAR}");
        }
        
        if (record.getMessageSortNum() != null) {
            sql.SET("message_sort_num = #{messageSortNum,jdbcType=INTEGER}");
        }
        
        if (record.getMessageType() != null) {
            sql.SET("message_type = #{messageType,jdbcType=INTEGER}");
        }
        
        if (record.getStatus() != null) {
            sql.SET("status = #{status,jdbcType=INTEGER}");
        }
        
        if (record.getCreateTime() != null) {
            sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateTime() != null) {
            sql.SET("update_time = #{updateTime,jdbcType=TIMESTAMP}");
        }
        
        sql.WHERE("id = #{id,jdbcType=BIGINT}");
        
        return sql.toString();
    }
}